Optional Sora.f
cr .( Loading SORA p.. )


Only Forth Definitions

Requires SORA\Tasks
Requires SORA\Tweening
Requires SORA\Images
Requires SORA\Tilemap-display

Requires SORA\Transformations
Requires SORA\Vertices
Requires SORA\Motifs

Requires SORA\Vbufs
Requires SORA\Sprites
Requires SORA\Text
Requires SORA\Drawing

Requires SORA\Collisions

Requires FixedPoint.f
Requires Vectors.f

type: image-based
   image pointer img
end-type

image-based extend: tileset
   int.field tilew
   int.field tileh
end-type


method: tileset.init  ( tilew tileh image tileset -- )
   img ! tileh ! tilew ! ;

: tileset.make
   any.make  lastbody @ init ;

: tileset.dims  tilew.2@ ;


motif extend: tilemap
   tileset.pointer ts
   short.pointer mapdata
   short.field mapw
   short.field maph
   fixed.field scrollx
   fixed.field scrolly
end-type

method: tilemap.[] ( col row tilemap -- short )
   mapw.@ * + mapdata.[] ;

: tilemap.dims  mapw.2@ ;

macro: tilemap.tilew   ts.tilew.@ ;
macro: tilemap.tileh   ts.tileh.@ ;
macro: tilemap.tiledims   ts.tilew.2@ ;

method: tilemap.draw
      scrollx.@ p>s tilew /mod
      scrolly.@ p>s tileh /mod  locals| row ofsy col ofsx |
      push-modelview
      transform.gltransform3d
      ofsx negate ofsy negate at
      tiledims 2dup to (tileh) to (tilew)
         ts.img.bindtex
      col row this.[]
         mapw.@
         w.@ p>s tilew / ofsx if 1 + then
         h.@ p>s tileh / ofsy if 1 + then
         draw-tilemap
      pop-modelview ;

: tilemap.init ( tileset mapw maph mapdata tilemap -- )
      super.construct
      mapdata.! maph.! mapw.! ts.!
      dims 2s>p ts.dims 2s>p 2mul h.! w.!
      show:[ draw ;] ;

\ max pixel dims are 65535.0 x 65535.0
\ mapw & maph specified here are in TILES.

: tilemap.make  ( tileset mapw maph -- <name> )
   any.make  here >r 2dup * 2* allot r> lastbody @ tilemap.init ;

Requires SORA\Spritesets
Requires SORA\Sprite-animation

Only Forth Definitions

: init-all
   load-gl-extensions
   reset-gl
   init-text-display
   init-tilemap-display
   init-vbufs
   init-drawing
   unbind-vbo
   reset-gl
   2dmode
   init-input
   init-textures ;

: end-frame
   seki-end-frame
   poll-all ;
